# Neuron Function For Kuro Project
# Verision: 0.1
# -By TRI_Kannmu 2021/11/5
import numpy as np
import Activation_Funcation as AF

Neuron_Count = 0

class Neuron:
    # Neuron Class Methods For Neuron
    def __init__(self):
        global Neuron_Count
        self.ID = Neuron_Count # Divide Neuron ID
        self.Neuro_Transmitter = []
        self.Output = 0
        Neuron_Count += 1

    # Set Weights And Bias For This Neuron
    def Set_WAB(self, weights, bias):
        weights = np.array(weights)
        bias = np.array(bias)
        self.weights = weights
        self.bias = bias
        self.Neuro_Transmitter = np.zeros(len(weights))
    
    def STDP(self,inputs,DOP):
        for i in range(len(self.weights)):
            self.weights[i] += inputs[i]*self.Output*DOP
            self.weights[i] = AF.Limit(self.weights[i])

    def Weight_Decrease(self):
        self.weights -= 0.1

    # Step Function For Neuron Simulate
    def Step(self, inputs, DOP):
        for i in inputs:
            i = AF.Limit(i)
        total = np.dot(self.weights, inputs) + self.bias + 0.01*np.random.rand()
        self.Output = AF.sigmoid(total) 
        self.STDP(inputs, DOP)
        self.Weight_Decrease()
        return self.Output 

# print(0.05*np.random.rand())


# Net = [Neuron() for i in range(2)]
# Net[1].Set_WAB([0.5],[0.5])
# Net[0].Set_WAB([0.5],[0.5])
# # Net[0].Step([0.5])
# for i in range(50):
#     Net[1].Step([Net[0].Step([0.5])])
#     print(Net[1].weights, Net[0].Output,Net[1].Output,Net[1].Neuro_Transmitter)



# A = 0
# for i in range(10):
#     A = AF.Neuro_Transmitter(A,0.5) 
#     print(A)

# inputs = np.array([1,2,3])
# Neuro_Transmitter = np.array([1,2,3])
# inputs = inputs * Neuro_Transmitter
# inputs = np.dot(inputs.T, Neuro_Transmitter).T
# print(inputs)
